<?php

namespace App\Listeners;

use App\Events\OrderEvent;
use Cisco\Aliyunsms\Facades\Aliyunsms;
use Illuminate\Config\Repository;


class sendSMS
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  \App\Events\OrderEvent  $event
     * @return void
     */
    public function handle(OrderEvent $event)
    {
        //发送物流通知短信
        $SignName    = env('ALIYUN_SIGN_NAME');          //模板签名
        $TemplateCode= env('ALIYUN_TEMPLATECODE');         //模板CODE
        $customer_name = $event->finishProduct->order->customer->customer_name;
        $product_name = $event->finishProduct->order->product_name->product_name;
        $model_number = $event->finishProduct->order->model_number_name->model_number;
        $delivery_time = $event->finishProduct->delivery_time;
        $logistics_info = $event->finishProduct->logistics_info;
        //$phone = $event->order_model->order->customer->contact_phone;
        $phone = 15135970424;
        //阿里云模板里面的变量
        $TemplateParam = [
            "customer_name"    => $customer_name,
            "product_name" => $product_name,
            "model_number"    => $model_number,
            "delivery_time" => $delivery_time,
            "logistics_info"  => $logistics_info,
        ];
        p($TemplateParam);

        $send = Aliyunsms::sendSms(strval($phone), $SignName, $TemplateCode, $TemplateParam);
        p($send);
        if ($send->Code == 'OK') {
            $res = ['code'=>0,'msg'=>'success','data'=>''];
        } else {
            $res = ['code'=>3004,'msg'=>$send->Message,'data'=>$send];
        }


    }
}
